import 'dart:math';
import 'package:get/get.dart';
import 'state.dart';

class PwdLogic extends GetxController {
  final PwdState state = PwdState();
  var code = "";
  @override
  void onInit() {
    getCode();
    super.onInit();

  }
  //用户隐私协议选中或未选中
  void updateUserPrivary() {
    state.isAgreeUserPrivary = !state.isAgreeUserPrivary;
    update();
  }

  // 调用随机数方法
  getCode(){
    code="";
    String alphabet = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
    for (var i = 0; i < 4; i++) {
      String charOrNum = Random().nextInt(2) % 2 == 0 ? "char" : "num";
      switch (charOrNum) {
        case "char":
          code += alphabet[Random().nextInt(alphabet.length)];
          break;
        case "num":
          code += Random().nextInt(9).toString();
          break;
      }
      update();
    }
  }
}
